package chapter06

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/9 5:45 PM
 */
object Test05_COnstructor {

  def main(args: Array[String]): Unit = {
    val student1 = new Student1()
    student1.Student1()

    val student2 = new Student1("zs")
    println("="*20)
    val student3 = new Student1("zs", 20)
  }
}

class Student1() {
  var name: String = _
  var age: Int = _
  println("1.主构造方法被调用")

  // 声明辅助构造方法
  def this(name: String) {
    this() // 直接调用主构造器
    println("2. 辅助构造方法一被调用")
    this.name = name
    println(s"name: $name age: $age")
  }

  def this(name: String, age: Int) {
    this(name)
    println("3. 辅助构造方法2被调用")
    this.age = age
    println(s"name: $name age: $age")

  }

  def Student1(): Unit = {
    println("一般方法被调用")
  }
}